const _ = require("../../utils/index")
Page({
    data: {
        tabs: [],
        loading: true,
        autoFix: true,
        activeTab: 0,
        swiperHeight: 3600,
        shopping: [],
        empty:{}
    },

    onLoad() {
        _.db.cloudGet("libs","all").then(res=>{
            this.setData({
                tabs:res
            })
        })
    },
    //页面显示（实时刷新）
    onReady() {
        let shopping = []
        _.db.cloudGet("doctors", "all").then(res => {
            shopping = res
            this.shopping = res
            this.setData({
                shopping,
                loading:false
            })
            this.autoHeight()
        })
    },
    onTabClick(e) {
        const index = e.detail.index
        const tabs = this.data.tabs
        // console.log("当前标签项->",tabs[index].title)
        this.setData({
            activeTab: index
        })
        // this.autoHeight()
    },

    onChange(e) {
        const index = e.detail.index
        const tabs = this.data.tabs
        // console.log("当前标签项->", tabs[index].title)
        this.setData({
            activeTab: index
        })
    },
    autoHeight() {
        let index = this.data.activeTab
        const query = wx.createSelectorQuery()
        query.select('#card-' + index).boundingClientRect()
        query.exec(res => {
            console.log(res[0])
            console.log(res[0].height)
            this.setData({
                swiperHeight: res[0].height + 15
            })
            console.warn("自动调整高度成功！！")
        })
    },
    //展现商品详情页
    showDetail(e) {
        let current = e.currentTarget.dataset.item
        console.log(current)
        let goodsOfStr = JSON.stringify(current)
        wx.navigateTo({
            url: '../interviewDetail/interviewDetail?detail=' + goodsOfStr,
        })
    }
})